#!/bin/bash
set -e

cd ${JM_SHARE_DIR}

# 根据信任证书选项设置SVN参数
SVN_EXTRA_OPTS=""
if [[ "${JIANMU_TRUST_CERT}" == "true" ]]; then
    SVN_EXTRA_OPTS="--trust-server-cert --non-interactive"
    echo "信任SVN证书：已启用"
else
    echo "信任SVN证书：未启用"
fi

# svn checkout拉取代码
if [[ -z ${JIANMU_CODE_VERSION} ]]; then
  svn checkout ${JIANMU_CODE_URL} --username ${JIANMU_SVN_USERNAME} --password ${JIANMU_SVN_PASSWORD} ${SVN_EXTRA_OPTS}
else
  svn checkout ${JIANMU_CODE_URL} -r${JIANMU_CODE_VERSION} --username ${JIANMU_SVN_USERNAME} --password ${JIANMU_SVN_PASSWORD} ${SVN_EXTRA_OPTS}
fi

engineering_name=$(echo ${JIANMU_CODE_URL##*/})
cd ${engineering_name}
svn info

echo "resultFile:"
echo -e "{\"code_path\":\"${JM_SHARE_DIR}/${engineering_name}\"}" > resultFile
mv resultFile /usr

cat /usr/resultFile